package com.scyshkj.university.wechat.pay;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by 唐旭 on 2016/11/20.
 */
@Controller
@RequestMapping("/wechat")
public class WechatLoginController {
    @Autowired
    private WechatLoginService wechatLoginService;

    @RequestMapping("/login")
    public String login(String code) {
        if (StringUtils.isEmpty(code)) {
            return "redirect:/unauthorized.html";
        }
        String result = wechatLoginService.loginByCode(code);
        if (!StringUtils.isEmpty(result)) {
            return "redirect:/unauthorized.html";
        }
        return "redirect:/index";
    }
}
